home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / GnuControl.h < prev    next >
C/C++ Source or Header  |  2000-07-15  |  4KB  |  159 lines

  1. #if !defined(AFX_GNUCONTROL_H__60210B40_1340_11D4_ACF2_00A0CC533D52__INCLUDED_)
  2. #define AFX_GNUCONTROL_H__60210B40_1340_11D4_ACF2_00A0CC533D52__INCLUDED_
  3.  
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. // GnuControl.h : header file
  8. //
  9.  
  10. #include "packet.h"            // Packet type definitions
  11. #include "GnuHash.h"
  12.  
  13. #pragma warning (disable : 4786)
  14.  
  15. #include <string>
  16. #include <list>
  17. #include <map>
  18.  
  19. class CGnucleusDoc;
  20. class CGnuSock;
  21. class CGnuTransfer;
  22.  
  23. struct CompareGuids {
  24.     bool operator () (const GUID& left, const GUID& right) const
  25.     {
  26.     return (::memcmp (&left, &right, sizeof(GUID)) < 0);
  27.     }
  28. };
  29.  
  30. typedef struct
  31. {
  32.     CGnuSock * ConnectedSock;
  33.     CString SearchString;
  34.     GUID ClientGuid;
  35.     GUID Origin;
  36.     IP Host;
  37.     WORD localPort;
  38.     bool bIsMatch;
  39.  
  40. }SearchQueryItem, *LPSearchQueryItem;
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CGnuControl command target
  44.  
  45. class CGnuControl : public CAsyncSocket
  46. {
  47.     DECLARE_DYNCREATE(CGnuControl)
  48.  
  49. // Attributes
  50. public:
  51.     
  52. // Operations
  53. public:
  54.     CGnuControl();
  55.     CGnuControl(CGnucleusDoc *DocLink);
  56.     virtual ~CGnuControl();
  57.  
  58.     void StartListening();
  59.  
  60.     BOOL AddNode(CString Host, CString Port);
  61.     void RemoveNode(CString Host, CString Port);
  62.     CGnuSock* GetNode(CString);
  63.  
  64.     void AddTransfer(QueryItem File, SOCKET sock = NULL);
  65.     void RemoveTransfer(int row, char type);
  66.     CGnuTransfer* GetTransfer(int row, char type);
  67.  
  68.     void NewPushRequest(QueryItem File);
  69.  
  70.     DWORD GetHostCount();
  71.  
  72.     // Pass packets to all other nodes, special routing here also
  73.     void Pass_Raw(CGnuSock *, byte *, int);
  74.  
  75.     void Broadcast_Ping(packet_Ping *, int, CGnuSock *);
  76.     void Broadcast_Query(packet_Query *, int, CGnuSock *);
  77.  
  78.     void Route_Pong(packet_Pong *, int, key_data *);
  79.     void Route_QueryReply(packet_QueryReply *, int, key_data *);
  80.     void Route_Push(packet_Push *, int, key_data *);
  81.  
  82.     int RunningThreads;
  83.  
  84.     // Localhost info
  85.     CString localHost;
  86.     DWORD localPort;
  87.  
  88.     // Our client's 128bit ID
  89.     GUID ClientGUID;
  90.  
  91.  
  92.     typedef std::map <GUID, CGnuSock*, CompareGuids> GuidHash;
  93.     GuidHash m_cache;
  94.  
  95.     CGnuHash HashClientTable;    // Stores client values from Query Replies
  96. //    CGnuHash HashTable;            // Stores GUIDs from Pings and Queries
  97.     CGnuHash SendTable;            // Stores GUIDs of sent packets
  98.  
  99.  
  100.  
  101.     // Statistics
  102.     DWORD BytesIn;
  103.     DWORD BytesOut;
  104.     
  105.     double long totalPings,   totalPongs,
  106.                 totalPushes,  totalUnknowns,
  107.                 totalQueries, totalQueryReplies,
  108.  
  109.                 totalTTLs,    totalTTLsBig,
  110.                 totalHops,    totalHopsBig;
  111.  
  112.     // Pointer to the document
  113.     CGnucleusDoc *Doc;
  114.  
  115. // Overrides
  116. public:
  117.     DWORD m_dwTotalBytesIn;
  118.     DWORD m_dwTotalBytesOut;
  119.     DWORD m_dwBytesPerSecIn;
  120.     DWORD m_dwBytesPerSecOut;
  121.     void OnTimer();
  122.     bool PopQueryFromQueue(SearchQueryItem & _search_item);
  123.     void PushQueryToQueue(CGnuSock * _lp_sock);
  124.  
  125.     // ClassWizard generated virtual function overrides
  126.     //{{AFX_VIRTUAL(CGnuControl)
  127.     public:
  128.     virtual void OnAccept( int nErrorCode );
  129.     //}}AFX_VIRTUAL
  130.  
  131.     // Generated message map functions
  132.     //{{AFX_MSG(CGnuControl)
  133.         // NOTE - the ClassWizard will add and remove member functions here.
  134.     //}}AFX_MSG
  135.  
  136. // Implementation
  137. protected:
  138.     UINT QueriesSearchThread();
  139.     static UINT staticQueriesSearchThread(LPVOID);
  140.     CWinThread * m_QueriesSearchThreadHandle;
  141.     CCriticalSection m_QueryListCriticalSection;
  142.     CEvent m_EventQueriesEND;
  143.     CEvent m_EventQueriesWaiting;
  144.     std::list<SearchQueryItem> m_SearchQueries;
  145.  
  146.     void m_Initialize (void);
  147.     CGnuSock *NodeList;
  148.     CGnuTransfer *TransferList;
  149.  
  150.     std::list<QueryItem> m_PushRequests;
  151. };
  152.  
  153. /////////////////////////////////////////////////////////////////////////////
  154.  
  155. //{{AFX_INSERT_LOCATION}}
  156. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  157.  
  158. #endif // !defined(AFX_GNUCONTROL_H__60210B40_1340_11D4_ACF2_00A0CC533D52__INCLUDED_)
  159.